home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-28 | 4.5 KB | 257 lines | [TEXT/MPS ] |
- /*
- File: HalfGateway.cp
-
- Contains: xxx put contents here xxx
-
- Written by: Tim Harnett
-
- Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <5> 2/15/95 TMH added GetSlot(slotCID)
- <4> 12/12/94 TMH modified so slot Id is written only once
- <3> 10/11/94 TMH CommThread integration
- <2> 9/21/94 TMH Use new Debug.cp ASSERT stuff
- <1> 9/20/94 TMH Abandon RoadsideRest embrace Mercury
- <2> 9/9/94 TMH TIncoming/TOutgoing adaptations
- 3/29/94 TMH xxx put comment here xxx
-
- To Do:
- */
-
-
- #ifndef __OCEERRORS__
- #include "OCEErrors.h"
- #endif
-
-
- #ifndef __Debug__
- #include "Debug.h"
- #endif
-
- #ifndef __PLSTRINGFUNCS__
- #include "PLStringFuncs.h"
- #endif
-
-
- #ifndef __Globals__
- #include "Globals.h"
- #endif
-
- #ifndef __FileUtils__
- #include "FileUtils.h"
- #endif
-
- #ifndef __Application__
- #include "Application.h"
- #endif
-
- #ifndef __CRecordID__
- #include "CRecordID.h"
- #endif
-
- #ifndef __CAttribute__
- #include "CAttribute.h"
- #endif
-
- #ifndef __MSAMSlot__
- #include "MSAMSlot.h"
- #endif
-
-
- #ifndef __HalfGateway__
- #include "HalfGateway.h"
- #endif
-
-
- #ifndef __Letter__
- #include "Letter.h"
- #endif
-
-
- #ifndef __UFAILURE__
- #include "UFailure.h"
- #endif
-
- #ifndef __LogErrors__
- #include "LogErrors.h"
- #endif
-
- #pragma segment AOCEHalfGateway
-
- //--------------------------------------
- // T A O C E H a l f G a t e w a y
- //--------------------------------------
-
- //-------------------------------------------------------------------------------------
- TAOCEHalfGateway::TAOCEHalfGateway()
- {
- fMSAMRecord = 0;
-
- for(int i= 0; i<kMaxSlots; i++ )
- fSlotList[i] = 0;
- }
-
-
-
- //-------------------------------------------------------------------------------------
- pascal OSErr TAOCEHalfGateway::BuildSlotListCallBack(long clientData, const AttributePtr attribute)
- {
-
- TAOCEHalfGateway* thisAOCEHalfGateway = (TAOCEHalfGateway*)clientData;
-
- PackedRecordIDPtr packedRID;
- RecordID rid;
-
- packedRID = (PackedRecordIDPtr) attribute->value.bytes;
- OCEUnpackRecordID(packedRID,&rid);
-
- FailInfo fi;
- Try(fi) {
-
- thisAOCEHalfGateway->FocSlot(rid.local.cid);
- fi.Success();
-
- } else {
- LogError(fi.error); // we are in a call back. DO NOT ReSignal()
- }
-
- return 0;
- }
-
-
- //-------------------------------------------------------------------------------------
- TMSAMSlot* TAOCEHalfGateway::FocSlot(CreationID msamRecordCID)
- {
-
- // Find or create a slot record.
-
-
- TMSAMSlot* slot = 0;
-
- for(int i=0; i<kMaxSlots; i++ ) {
- if( (fSlotList[i] != 0) && (fSlotList[i]->GetSlotCID() == msamRecordCID) ) {
- slot = fSlotList[i];
- break;
- }
- }
-
-
- if( slot == 0 ) {
-
- FailInfo fi;
- Try(fi) {
-
- slot = new TMSAMSlot;
- slot->IMSAMSlot(&msamRecordCID);
- this->AddSlot(slot);
- fi.Success();
-
- } else {
- fi.ReSignal();
- }
-
- }
-
-
- return slot;
-
-
- }
-
-
- //-------------------------------------------------------------------------------------
- OSErr TAOCEHalfGateway::SetupSlots(CreationID msamRecordCID)
- {
- OSErr osErr = 0;
-
- fMSAMRecord = new CRecordID(gKeyChainDSRefnum,msamRecordCID);
-
- // Build Slot List.
- CAttribute slotRecords(kMailServiceAttrTypeNum);
- slotRecords.LookupValues(fMSAMRecord,(CAttributeValueCallBack)BuildSlotListCallBack,(long)this);
-
-
- // for each slot, get the slot data from the mailservice record and activate the slot
- TMSAMSlot* msamSlot = 0;
- for(int i= 0; i<kMaxSlots; i++ ) {
- if( (msamSlot = fSlotList[i]) != 0 ) {
- osErr = msamSlot->SetSlotInfo();
- if( osErr == noErr )
- msamSlot->Activate();
- }
- }
-
- return osErr;
-
- }
-
-
-
- //-------------------------------------------------------------------------------------
- TMSAMSlot* TAOCEHalfGateway::GetSlot(short slotID)
- {
-
-
- TMSAMSlot* slot = 0;
-
- for(int i= 0; i<kMaxSlots; i++ )
- if( (fSlotList[i] != 0 ) && fSlotList[i]->GetSlotID() == slotID ) {
- slot = fSlotList[i];
- break;
- }
-
-
- ASSERT(slot != 0);
-
- return slot;
-
-
- }
-
- //-------------------------------------------------------------------------------------
- TMSAMSlot* TAOCEHalfGateway::GetSlot(CreationID slotCID)
- {
-
-
- TMSAMSlot* slot = 0;
-
- for(int i= 0; i<kMaxSlots; i++ ) {
-
- if( (fSlotList[i] != 0 ) ) {
- CreationID cid = fSlotList[i]->GetSlotCID();
- if( cid == slotCID )
- slot = fSlotList[i];
- break;
- }
-
- }
-
- ASSERT(slot != 0);
-
- return slot;
-
-
- }
-
-
-
- //-------------------------------------------------------------------------------------
- void TAOCEHalfGateway::AddSlot(TMSAMSlot* msamSlot)
- {
-
- for(int i= 0; i<kMaxSlots; i++ )
- if( fSlotList[i] == 0 ) {
- fSlotList[i] = msamSlot;
- fNumberOfSlots++;
- break;
- }
-
-
- ASSERTPRINT(i != kMaxSlots, ("cannot add new slot TAOCEHalfGateway::AddSlot"));
-
- }
-
-
-